package com.itdaan.portal.business.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

/**
 * Servlet请求监听器
 * @author www.itdaan.com
 *
 */
public class RequestListener implements ServletRequestListener {
	
	public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
		
	}

	public void requestInitialized(ServletRequestEvent servletRequestEvent) {
		HttpServletRequest request = (HttpServletRequest)servletRequestEvent.getServletRequest();//获取request对象
		ServletContext application = request.getSession().getServletContext();//获取servletContext对象
		if(application.getAttribute("path") == null){//设置全局的访问路径
			String port = request.getServerPort() == 80 ? "" : ":".concat(request.getServerPort()+"");
			String path = request.getScheme().concat("://").concat(request.getServerName()).concat(port).concat(request.getContextPath());
			application.setAttribute("path", path);
		}
	}

	

}
